package com.alex.algorithm.easy;

public class HouseRobber {

    public static void main(String[] args) {
        System.out.println(maxTotal(new int[]{1,2,3,1}));
        System.out.println(maxTotal(new int[]{2,7,9,3,1}));
    }

    public static int maxTotal(int[] moneys) {
        if (moneys == null || moneys.length == 0) {
            return 0;
        }
        if (moneys.length == 1) {
            return moneys[0];
        }
        int prev = moneys[0];
        int cur = Math.max(moneys[0], moneys[1]);
        for (int i = 2; i < moneys.length; ++i) {
            int temp = cur;
            cur = Math.max(moneys[i] + prev, cur);
            prev = temp;
        }
        return cur;
    }
}
